package cn.newgrand.netcall.ui;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import org.jivesoftware.resource.SparkRes;
import org.jivesoftware.spark.ui.ChatRoom;
import org.jivesoftware.spark.ui.ChatRoomButton;
import org.jivesoftware.spark.ui.ChatRoomClosingListener;

import cn.newgrand.netcall.expert.transcript.HistoryMessageManager;

public class ChatTranscriptDecorator implements ActionListener,ChatRoomClosingListener{
	
	private ChatRoom chatRoom;
	private ChatRoomButton chatTranscriptButton;
	
	public ChatTranscriptDecorator(){
	}
	
	public ChatTranscriptDecorator(ChatRoom chatRoom){
		this.chatRoom = chatRoom;
		chatRoom.addClosingListener(this);
		chatTranscriptButton = new ChatRoomButton(SparkRes.getImageIcon(SparkRes.GTALK_TRANSPORT_ACTIVE_IMAGE));
		chatRoom.getToolBar().addChatRoomButton(chatTranscriptButton);
		chatTranscriptButton.setToolTipText("查看专家的聊天记录");
		chatTranscriptButton.addActionListener(this);
	}

	@Override
	public void closing() {
		chatRoom.removeClosingListener(this);
		chatTranscriptButton.removeActionListener(this);
	}

	@Override
	public void actionPerformed(ActionEvent arg0) {
		HistoryMessageManager.getInstance().showTranscript(chatRoom.getRoomname());
	}

}
